package com.apexwear.apexutils.ui;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.apex.bluetooth.callback.GeneralCallback;
import com.apex.bluetooth.core.EABleManager;
import com.apex.bluetooth.enumeration.EABleConnectState;
import com.apex.bluetooth.model.EABleDev;
import com.apexwear.apexutils.R;
import com.apexwear.apexutils.databinding.ActivityResetBinding;
import com.apexwear.apexutils.utils.ShowToast;

public class ResetActivity extends AppCompatActivity {
    ActivityResetBinding dataBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_reset);
        dataBinding.tooBar.setNavigationIcon(R.mipmap.exit_page);
        setSupportActionBar(dataBinding.tooBar);
        getSupportActionBar().setTitle(null);
        dataBinding.tooBar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        dataBinding.sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (EABleManager.getInstance().getDeviceConnectState() == EABleConnectState.STATE_CONNECTED) {
                    EABleDev eaBleDev = new EABleDev();
                    eaBleDev.setE_ops(EABleDev.DevOps.restore_factory);
                    EABleManager.getInstance().setDeviceOps(eaBleDev, new GeneralCallback() {
                        @Override
                        public void result(final boolean b, int i) {

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    if (b) {
                                        ShowToast.show(ResetActivity.this, getString(R.string.set_success));
                                    } else {
                                        ShowToast.show(ResetActivity.this, getString(R.string.set_fail));
                                    }
                                }
                            });

                        }

                        @Override
                        public void mutualFail(int i) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    ShowToast.show(ResetActivity.this, getString(R.string.set_fail));

                                }
                            });
                        }
                    });
                }
            }
        });
    }
}
